package com.nf.sms.dao.impl;

import com.nf.sms.dao.UserDao;
import com.nf.sms.entity.User;
import com.nf.sms.utils.DbUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @AUTHOR CJ
 * <p>
 * *@DATE 2024 - 10 - 15
 */
public class UserDaoImpl implements UserDao {
    @Override
    public int insert(User user) {
        int r = 0;
        Connection conn = null;
        PreparedStatement pr = null;

        try {
            conn = DbUtil.getConnection();
            String sql = "insert into users(username,password,phone,email) values (?,?,?,?)";
            pr = conn.prepareStatement(sql);
            pr.setString(1,user.getUsername());
            pr.setString(2,user.getPassword());
            pr.setString(3,user.getPhone());
            pr.setString(4,user.getEmail());
           r = pr.executeUpdate();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            DbUtil.close(null,pr,conn);
        }
        return r;
    }

    @Override
    public User selectByName(String username) {
        return null;
    }

    @Override
    public int updatePassword(String username, String newPass) {
        return 0;
    }
}
